package flc.ast.activity;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import com.stark.calculator.tax.CustomWageActivity;
import com.stark.calculator.tax.constant.TaxConst;

import flc.ast.BaseAc;
import flc.ast.R;
import flc.ast.databinding.ActivityMySelectCityBinding;
import flc.ast.fragment.MySelectCityFragment;

public class MySelectCityActivity extends BaseAc<ActivityMySelectCityBinding> {

    private static final String CUSTOM = "自定义";
    private static final int REQ_CUSTOM_WAGE = 1;

    @Override
    protected int onCreate() {
        return R.layout.activity_my_select_city;
    }

    @Override
    protected void initView() {
        mDataBinding.ivSelCityBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });
        MySelectCityFragment fragment = new MySelectCityFragment();
        fragment.setListener(cityWage -> {
            if (CUSTOM.equals(cityWage.cityName)) {
                CustomWageActivity.start(this, cityWage, REQ_CUSTOM_WAGE);
            } else {
                //设置结果，finish
                Intent data = new Intent();
                data.putExtra(TaxConst.KEY_WAGE, cityWage);
                setResult(RESULT_OK, data);
                finish();
            }

        });
        getSupportFragmentManager().beginTransaction().replace(R.id.frContainer,fragment).commit();
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == RESULT_OK) {
            if (requestCode == REQ_CUSTOM_WAGE) {
                //直接将结果传递给请求页面
                setResult(RESULT_OK, data);
                finish();
            }
        }
    }
}